/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package penjadwalan;

import java.util.ArrayList;

/**
 *
 * @author masphei
 */
public class Fitness {
    private ArrayList<Machine> ListMachine;
    private int Modal;
    private final int GENOTYPE_SIZE;
    public Fitness(ArrayList<Machine> _machine, int _modal, int _SIZE){
        ListMachine = _machine;
        Modal = _modal;
        GENOTYPE_SIZE = _SIZE;
    }
    public int calculate(Candidate Chromosom){
        // merupakan fungsi fitnes yang mengembalikan nilai fitnes yang akan dibandingkan antara satu kromosom dengan kromosom lainnya
        int ModalAwal = Modal;
        int sum = 0;
        boolean valid = false;
        for(int i=1;i<=Chromosom.SIZE;i++){
            valid = false;
            if(ModalAwal>Modal){
                ModalAwal-=Modal;
                if(calculateBebanKerjaPerHari(Chromosom, i-1)>0){
                    if(calculateBebanKerjaPerPeriode(Chromosom, i-1)>0){
                        if(ListMachine.get(Chromosom.getGenotype(i)).getDependency()==0){
                            valid = true;
                        }else{ // Dependency
                            if(isProductExist(Chromosom, i-1)){
                                valid = true;
                            }else{
                            }
                        }
                    }else{ // W = 0
                    }
                }else{ // T = 0
                }
            }else{ // Modal habis
            }
            
            if(valid){
                if(isOverload(Chromosom, i-1)){
                    sum+= (ListMachine.get(Chromosom.getGenotype(i)).getProduktivitas()*ListMachine.get(Chromosom.getGenotype(i)).getCostOverload());
                }else{ // Cost Overload
                    sum+= ListMachine.get(Chromosom.getGenotype(i)).getProduktivitas();
                }                
            }
        }
        return sum;
    }
    public boolean isProductExist(Candidate Chromosom, int indexArray){
        return true;
    }
    public boolean isOverload(Candidate Chromosom, int indexArray){
        return true;
    }
    public int calculateBebanKerjaPerHari(Candidate Chromosom, int indexArray){
        return 1;
    }
    public int calculateBebanKerjaPerPeriode(Candidate Chromosom, int indexArray){
        return 1;
    }
    public Chromosom sortFitness(){
        // fungsi untuk mengurutkan chromosom berdasarkan nilai fitnes functionnya
        return new Chromosom();
    }
    
}
